package com.pkk.alert.web.config.content;

import com.pkk.alert.web.config.properties.ScheduleInfo;
import com.pkk.alert.web.config.properties.ScheduleRuntimeVo;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import lombok.NonNull;

/**
 * 任务中心
 *
 * @author peikunkun
 * @version V1.0
 * @date 2020-11-04 15:08
 **/
public class ScheduleContent {


  /**
   * 失败的定时任务-[失败的定时任务,不会在重启]
   */
  public static final ConcurrentHashMap<String, String> FAIL_SCHEDULE = new ConcurrentHashMap<>();

  /**
   * 成功要执行的定时任务
   */
  public static final ConcurrentHashMap<String, ScheduleInfo> SUCCESS_SCHEDULE = new ConcurrentHashMap<>();
  /**
   * 取消的定时任务
   */
  public static final Set<String> CANCEL_SCHEDULE = new CopyOnWriteArraySet<>();

  /**
   * 正在运行的定时任务
   */
  public static final Map<String, ScheduleRuntimeVo> SCHEDULED_FUTURE_MAP = new ConcurrentHashMap<>();


  /**
   * 获取任务id依据全路径配置信息
   *
   * @return java.lang.String
   * @author peikunkun
   * @date 2020/11/4 0004 下午 3:13
   * @since
   */
  public static String getScheduleId(@NonNull String scheduleFullName) {
    return scheduleFullName.replaceFirst("com.pkk.schedule.info.", "");
  }


}
